package org.rcgwt.client.ui.validator.impl;

import org.rcgwt.client.ui.validator.IChecker;
import org.rcgwt.client.ui.validator.IClientValidatorContext;
import org.rcgwt.client.ui.validator.ISingleton;
import org.rcgwt.client.ui.validator.IValidatorElement;
import org.rcgwt.client.ui.validator.messages.Severity;

/**
 * Checker which checks if the string analyzed contains blank at head or queue
 * position
 * 
 * @author Elian ORIOU
 * 
 */

public class SkipBlankChecker implements IChecker, ISingleton {

	private static final SkipBlankChecker INSTANCE = new SkipBlankChecker();

	protected SkipBlankChecker() {

	}

	@Override
	public boolean check(IClientValidatorContext context, String s) {
		if (!s.startsWith(" ") && !s.endsWith(" ")) {
			return true;
		} else {
			context.addMessage(context.getMessagesProvider()
					.StructureErrorShort(), context.getMessagesProvider()
					.StructureError(), Severity.ERROR);
			return false;
		}
	}

	public static IValidatorElement getInstance() {
		return INSTANCE;
	}
}
